"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getApkInfo = exports.Platform = exports.generateFullDevice = exports.generateShortDevice = void 0;
const crypto_1 = require("crypto");
const constants_1 = require("./constants");
const randomString = (n, template = 'abcdef1234567890') => {
    const len = template.length
    return new Array(n).fill(false).map(() => template.charAt(Math.floor(Math.random() * len))).join('')
}
function generateImei() {
    let imei = `86${randomString(12, '0123456789')}`

    function calcSP(imei) {
        let sum = 0
        for (let i = 0; i < imei.length; ++i) {
            if (i % 2) {
                let j = parseInt(imei[i]) * 2
                sum += j % 10 + Math.floor(j / 10)
            } else {
                sum += parseInt(imei[i])
            }
        }
        return (100 - sum) % 10
    }

    return imei + calcSP(imei)
}
/** 生成短设备信息 */
function generateShortDevice(uin) {
    const randstr = (length, num = false) => {
        const map = num ? '0123456789' : '0123456789abcdef'
        return randomString(length, map)
    }
    return {
        "--begin--": "该设备为随机生成，丢失后不能得到原先配置",
        product: `ILPP-${randstr(5).toUpperCase()}`,
        device: `${randstr(5).toUpperCase()}`,
        board: `${randstr(5).toUpperCase()}`,
        brand: `${randstr(4).toUpperCase()}`,
        model: `ILPP ${randstr(4).toUpperCase()}`,
        wifi_ssid: `HUAWEI-${randstr(7)}`,
        bootloader: `U-boot`,
        android_id: `IL.${randstr(7, true)}.${randstr(4, true)}`,
        boot_id: `${randstr(8)}-${randstr(4)}-${randstr(4)}-${randstr(4)}-${randstr(12,)}`,
        proc_version: `Linux version 5.10.101-android12-${randstr(8)}`,
        mac_address: `2D:${randstr(2).toUpperCase()}:${randstr(2).toUpperCase()}:${randstr(2,).toUpperCase()}:${randstr(2).toUpperCase()}:${randstr(2).toUpperCase()}`,
        ip_address: `192.168.${randstr(2, true)}.${randstr(2, true)}`,
        imei: `${generateImei()}`,
        incremental: `${randstr(10).toUpperCase()}`,
        "--end--": "修改后可能需要重新验证设备",
    };
}
exports.generateShortDevice = generateShortDevice;
/** 生成完整设备信息 */
function generateFullDevice(d) {
    if (typeof d === "number")
        d = generateShortDevice(d);
    return {
        display: d.android_id,
        product: d.product,
        device: d.device,
        board: d.board,
        brand: d.brand,
        model: d.model,
        bootloader: d.bootloader,
        fingerprint: `${d.brand}/${d.product}/${d.device}:10/${d.android_id}/${d.incremental}:user/release-keys`,
        boot_id: d.boot_id,
        proc_version: d.proc_version,
        baseband: "",
        sim: "T-Mobile",
        os_type: "android",
        mac_address: d.mac_address,
        ip_address: d.ip_address,
        wifi_bssid: d.mac_address,
        wifi_ssid: d.wifi_ssid,
        imei: d.imei,
        android_id: d.android_id,
        apn: "wifi",
        version: {
            incremental: d.incremental,
            release: "10",
            codename: "REL",
            sdk: 29,
        },
        imsi: (0, crypto_1.randomBytes)(16),
        guid: (0, constants_1.md5)(Buffer.concat([Buffer.from(d.imei), Buffer.from(d.mac_address)])),
    };
}
exports.generateFullDevice = generateFullDevice;
// ----------
/** 支持的登录设备平台 */
var Platform;
(function (Platform) {
    Platform[Platform["Android"] = 1] = "Android";
    Platform[Platform["aPad"] = 2] = "aPad";
    Platform[Platform["Watch"] = 3] = "Watch";
    Platform[Platform["iMac"] = 4] = "iMac";
    Platform[Platform["iPad"] = 5] = "iPad";
})(Platform = exports.Platform || (exports.Platform = {}));
const mobile = {
    id: "com.tencent.mobileqq",
    app_key: '0S200MNJT807V3GE',
    name: "A8.9.50.f5a7d351",
    version: "8.9.50.10650",
    ver: "8.9.50",
    sign: Buffer.from([0xA6, 0xB7, 0x45, 0xBF, 0x24, 0xA2, 0xC2, 0x77, 0x52, 0x77, 0x16, 0xF6, 0xF3, 0x6E, 0xB6, 0x8D]),
    buildtime: 1676531414,
    appid: 16,
    subid: 537155551,
    bitmap: 150470524,
    sigmap: 16724722,
    subsigmap: 0x10400,
    sdkver: "6.0.0.2535",
    display: "Android",
    ssover: 19,
};
const watch = {
    id: "com.tencent.qqlite",
    app_key: '0S200MNJT807V3GE',
    name: "A2.0.8",
    version: "2.0.8",
    ver: "2.0.8",
    sign: Buffer.from([166, 183, 69, 191, 36, 162, 194, 119, 82, 119, 22, 246, 243, 110, 182, 141]),
    buildtime: 1559564731,
    appid: 16,
    subid: 537065138,
    bitmap: 16252796,
    sigmap: 16724722,
    subsigmap: 0x10400,
    sdkver: "6.0.0.2365",
    display: "Watch",
    ssover: 5
};
const hd = {
    id: "com.tencent.minihd.qq",
    app_key: '0S200MNJT807V3GE',
    name: "A5.9.3.3468",
    version: "5.9.3.3468",
    ver: "5.9.3",
    sign: Buffer.from([0xAA, 0x39, 0x78, 0xF4, 0x1F, 0xD9, 0x6F, 0xF9, 0x91, 0x4A, 0x66, 0x9E, 0x18, 0x64, 0x74, 0xC7]),
    buildtime: 1637427966,
    appid: 16,
    subid: 537128930,
    bitmap: 150470524,
    sigmap: 1970400,
    subsigmap: 66560,
    sdkver: "6.0.0.2487",
    display: "iMac",
    ssover: 12
};
const apklist = {
    [Platform.Android]: mobile,
    [Platform.aPad]: {
        ...mobile,
        subid: 537155599,
        display: 'aPad'
    },
    [Platform.Watch]: watch,
    [Platform.iMac]: { ...hd },
    [Platform.iPad]: {
        ...mobile,
        subid: 537155074,
        sign: hd.sign,
        name: 'A8.9.50.611',
        version: 'A8.9.50.611',
        sdkver: '6.0.0.2535',
        display: 'iPad'
    },
};

function getApkInfo(p) {
    return apklist[p] || apklist[Platform.Android];
}
exports.getApkInfo = getApkInfo;
